

package com.hazelcast.map.impl.operation;

import com.hazelcast.internal.serialization.Data;
import com.hazelcast.map.impl.MapDataSerializerHook;
import com.hazelcast.map.impl.operation.steps.RemoveOpSteps;
import com.hazelcast.map.impl.operation.steps.engine.State;
import com.hazelcast.map.impl.operation.steps.engine.Step;

public class RemoveOperation extends BaseRemoveOperation {

    protected boolean successful;

    public RemoveOperation() {
    }

    public RemoveOperation(String name, Data dataKey) {
        super(name, dataKey);
    }

    @Override
    protected void runInternal() {
        dataOldValue = mapServiceContext.toData(recordStore.remove(dataKey, getCallerProvenance()));
        successful = dataOldValue != null;
    }

    @Override
    public void afterRunInternal() {
        if (successful) {
            super.afterRunInternal();
        }
    }

    @Override
    public void applyState(State state) {
        super.applyState(state);
        successful = dataOldValue != null;
    }

    @Override
    public Step getStartingStep() {
        return RemoveOpSteps.READ;
    }

    @Override
    public boolean shouldBackup() {
        return dataOldValue != null;
    }

    @Override
    public int getClassId() {
        return MapDataSerializerHook.REMOVE;
    }
}
